/*
 * 文件名：UserFacade.java
 * 版权：MoonBox 
 * 修改人：Peter
 * 修改时间：2018年9月17日
 * 修改内容：新增
 */
package com.renzhebiao.lkang.facade;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.renzhebiao.lkang.entity.UserPO;
import com.renzhebiao.lkang.page.PageDTO;
import com.renzhebiao.lkang.page.PaginationDTO;
import com.renzhebiao.lkang.query.UserQuery;
import com.renzhebiao.lkang.service.IUserService;
import com.renzhebiao.lkang.utils.EmptyTools;
import com.renzhebiao.lkang.utils.PasswordEncoder;

import lombok.extern.log4j.Log4j;

/**
 * <p>
 * 
 * @author Peter
 * @since 1.0.0
 */
@Service
@Log4j
public class UserFacade {

    @Autowired
    private IUserService UserService;
    @Autowired
    PasswordEncoder      passwordEncoder;

    @Transactional
    public void add(UserPO po) {
        po.setPassword(passwordEncoder.encode(po.getPassword().trim()));
        this.UserService.add(po);
    }

    @Transactional
    public void edit(UserPO po) {
        if (EmptyTools.isNotNullOrEmpty(po.getPassword())) {
            po.setPassword(passwordEncoder.encode(po.getPassword().trim()));
        }
        this.UserService.edit(po);
    }

    /**
     * 逻辑删除
     * 
     * @param id
     */
    @Transactional
    public void delete(Long id) {
        this.UserService.delete(id);
    }

    /**
     * 查询列表
     * 
     * @return
     */
    public List<UserPO> getUserList(UserQuery po) {
        return this.UserService.getUserList(po);
    }

    /**
     * 查询单条
     * 
     * @return
     */
    public UserPO getUser(Long id) {
        return this.UserService.getUser(id);
    }

    /**
     * 分页查询
     * 
     * @param paging
     * @return
     */
    public PageDTO<UserPO> getUserByPage(PaginationDTO<UserQuery, Void> paging) {
        return this.UserService.getUserByPage(paging);
    }

}
